<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>返回数组中指定元素的下标</title>
    <script>
        function fundall(a, x) {
            var result = []
            var pos = 0
            while (pos < a.length) {
                pos = a.indexOf(x, pos)
                if (pos == -1) {
                    break;
                }
                result.push(pos)
                pos += 1
            }
            return result
        }

        function count(arr, item) {
            var number = 0
            for (var i = 0; i < arr.length; i++) {
                if (arr[i] == item) {
                    number++
                }
            }
            return number
        }
        var arr = new Array('a', 'b', 'd', 'd', 'c', 'd', 'd')
        alert(arr)
        document.write(fundall(arr, 'd') + '<br>')
        document.write(count(arr, 'd'))
    </script>
</head>

<body>

</body>

</html>